﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MainPage.xaml.cs" company="">
//   
// </copyright>
// <summary>
//   The main page.
// </summary>
// --------------------------------------------------------------------------------------------------------------------



using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

using cz.burger.windows.MDCCTaxi.Resources;

using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace cz.burger.windows.MDCCTaxi
{
    using System.Windows.Input;

    using Microsoft.Phone.Wallet;

    /// <summary>
    /// The main page.
    /// </summary>
    public partial class MainPage : PhoneApplicationPage
    {
        /// <summary>
        /// The model.
        /// </summary>
        public Model model = new Model();

        // Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPage"/> class.
        /// </summary>
        public MainPage()
        {
            InitializeComponent();
            DataContext = model;
            this.StartLoading();
        }

        private async void StartLoading()
        {
            await this.model.Login();
            if (model.Logged)
            {
                await this.model.LoadStatus();
            }
        }

        private async void RideBlock_OnTap(object sender, GestureEventArgs e)
        {
        }

        private async void ResultText_OnTap(object sender, GestureEventArgs e)
        {
            this.model.Reset();

            if (!this.model.Logged)
            {
                await this.model.Login();
            }

            if (this.model.Logged)
            {
                await this.model.LoadStatus();
            } 
        }
    }
}